package com.wyh.domain.vo.groupOne.utils.ThreemeterReadingExcelUtils;

import com.wyh.domain.dto.groupOne.threemeterAbout.threemeterReading.ThreemeterReadingDTO;
import com.wyh.domain.vo.groupOne.threemeterTree.threemeterReading.ThreemeterReadingExcelVO;

import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;

public class ThreemeterReadingConverter {

    public static List<ThreemeterReadingExcelVO> convertToExcelVOList(List<ThreemeterReadingDTO> dtoList) {
        AtomicInteger counter = new AtomicInteger(1);

        return dtoList.stream().map(dto -> ThreemeterReadingExcelVO.builder()
                .id(counter.getAndIncrement())  // 自增ID
                .nature(convertNature(dto.getNature()))
                .number(dto.getNumber())
                .name(dto.getName())
                .infoname(dto.getInfoname())
                .period(dto.getPeriod())
                .previousperiodtime(dto.getPreviousperiodtime())
                .previousreading(dto.getPreviousreading())
                .previoususage(dto.getPrevioususage())
                .readingtime(dto.getReadingtime())
                .reading(dto.getReading())
                .dosage(dto.getDosage())
                .ischarging(convertIsCharging(dto.getIscharging()))
                .build()
        ).collect(Collectors.toList());
    }

    private static String convertNature(Integer nature) {
        switch (nature) {
            case 0:
                return "水表";
            case 1:
                return "电表";
            case 2:
                return "气表";
            default:
                return "未知";
        }
    }

    private static String convertIsCharging(Integer ischarging) {
        return ischarging == 0 ? "未计费" : "已计费";
    }
}

